package com.example.activiti.config;

import com.example.activiti.common.MessageBody;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Mr.yuan
 * @version v1.0
 * @date 2019/11/12 13:19
 **/
@Slf4j
@RestControllerAdvice(annotations = RestController.class)
public class ExceptionAdvice {

    @ExceptionHandler(value = Exception.class)
    public MessageBody handleException(Exception ex, HttpServletRequest request){
        log.error("{} error-{}",request.getRemoteHost(),ex);
        return MessageBody.error(ex.getMessage());
    }
}
